//package com.godGuang.mine.config;
//
//import com.godGuang.mine.util.MailUtils;
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.RandomUtils;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.Queue;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//import java.util.concurrent.TimeUnit;
//
///**
// * @ClassName EmailConfig
// * @Author 张舒磊
// * @Date 2024/1/8 17:23
// * @Version 1.0
// * @Description TODO
// **/
//@Slf4j
//@Component
//public class EmailConfig {
//    @Autowired
//    private RedisTemplate<String, String> redisTemplate;
//
////    @Autowired
////    private JavaMailSender javaMailSender;
//
//
//    @RabbitListener(queuesToDeclare = {@Queue(name = "send_sms_queue_email")})
//    public void mqSendMessage(String email, Channel channel, Message message) {
//        log.info("邮箱消费者队列接收到消息，消息内容：{}", email);
//
//        String messageId = message.getMessageProperties().getMessageId();
//        try {
//            Long count = redisTemplate.opsForSet().add("send_sms_queue_email", messageId);
//            if (1 == count) {
//                //MimeMessage mimeMessage = javaMailSender.createMimeMessage();
//
//                MailUtils mailUtils = new MailUtils();
//                int code = RandomUtils.nextInt();
//                mailUtils.sendSimpleEmail(email, "修改密码", "验证码为：" + code);
//
//                //String code = RandomUtil.randomNumbers(4);
//
//                redisTemplate.opsForValue().set(email, code + "", 5, TimeUnit.MINUTES);
//
////
////                MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
////                helper.setFrom("2128364718@qq.com");
////                helper.setTo(email);
////                helper.setSubject("修改密码");
////                helper.setText("验证码为：" + code);
////                javaMailSender.send(mimeMessage);
//
//                channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//                log.info("邮箱消费者队列消费成功，消息内容：{}", email);
//            } else {
//                log.info("邮箱消费者队列消费重复，消息内容：{}", email);
//            }
//        } catch (Exception e) {
//            redisTemplate.opsForSet().remove("send_sms_queue_email", messageId);
//
//            try {
//                channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
//                log.info("邮箱消费者队列消费回退，消息内容：{}", email);
//            } catch (IOException ex) {
//                ex.printStackTrace();
//            }
//
//        }
//    }
//
//}
